Chris Pollett > Old Classes >
CS157a

( Print View )

Student Corner:
  [Grades Sec3]
  [Grades Sec4]

  [Submit Sec3]
  [Submit Sec4]

  [Email List Sec3]
  [Email List Sec4]

  [
Lecture Notes]

Course Info:
  [Texts & Links]
  [Topics]
  [Grading]
  [HW Info]
  [Exam Info]
  [Regrades]
  [Honesty]
  [Additional Policies]
  [Announcements]

HW Assignments:
  [Hw1]  [Hw2]  [Hw3]
  [Hw4]  [Hw5]

Practice Exams:
  [Mid1]  [Mid2]  [Final]

                           












HW#1 --- last modified March 02 2019 21:20:05..

Solution set.

Due date: Sep 12

Files to be submitted:
  Problems.txt
  SectionProf.java

Purpose: To start you thinking about the design problems that go into making a successful database or database management system. These problems include how the database should be broken into tables, what kind of queries will be made of the data, how to return answer sets for a query, how the target users can and will access the data.

Specification:

First, do the following problems out of Elmasri and Navathe: 1.11 and 2.11. Submit these in the plain text file Problems.txt. Then imagine you had the task of storing data about bank accounts and transactions on such accounts. What different attributes would you store? What ways would you group these attributes into tables? Write your answers to these two problems also in the file Problems.txt.

For the programming part of the assignment you will write a small Java (1.4.2 or 1.5) program which can be run from the command line with a line like:

java SectionProf filename1 filename2

Of course, filename1 and filename2 might be called something else. Your program treats filename1 as a file of Courses and treats filename 2 as a file of Sections. Each file is a sequence of lines delimited by a `\n'. A typical line of a Courses file might look like:

"CS157"  "Databases" "3"   "CS"

That is, it has the format: CourseNumber, CourseName, Credits, Department, where each item is in quotes and there are single tabs between items. A typical line of a Sections file might look like:

"5"   "CS157"  "Fall"   "2005"   "Pollett"

So it has the format: SectionNumber, CourseNumber, Semester, Year, Professor where each item is in quotes and there are single tabs between items.

The program SectionProf should output each CourseName taught by each professor. The data should be output on separate lines of the form: "Professor" "CourseName". The Professor and CourseName should be in quotes and separated by a tab. If a professor has taught seven courses he should appear in seven lines. If a course has been taught 20 times it should be listed twenty times. Note a professor can teach different sections of the same course as well as the same course in different semesters. Each time should count as one row output. Your program should note assume filename1 and filename2 can be completely read into memory. Your programs will be tested on large files and the virtual memory will be deliberately set to try to break your program. The files used to test your program will be published with the solution set. As an example of the kinds of programs I can use to test your code take a look at the following test program:

//HW1.java
import java.util.*;
import java.io.*;

/**

   This class consists of a bunch of public static methods used to test
   student programs for CS157A Fall 2005 HW1.

   This java file would typically be placed in the same directory
   as the file to be tested. Then to compile this file the line:
   
   javac HW1.java
   
   would be executed. This should also compile the student's program.
   Then to test the student's program the line

   java -Xmx1024k HW1

   would be used. The option -Xmx1024k sets the heaps maximum size to 1Mb.
   This is the smallest size Java allows. The code below then further
   wittles this down by creating a large array.

   @author Chris Pollett
   @version 7.9.2005
 
*/
public class HW1 
{

   /** 
       Creates a Courses file to be used in testing the students code
       The outFile.print lines below give the format for a line in this
       file. Also look at the HW description.

       @param size - numbers of rows to be output in courses files 
         (must be divisible by 2) 

   */
   public static void createCourses(int size)
   {
      try
      {
         System.out.println("size"+size);
         PrintStream outFile = new PrintStream(
            new FileOutputStream(COURSES_NAME));
         
         int j = 0;
         int k = 0;
         for(int i =0; i < size; i++)
         {  

            outFile.print("\"CS"+i+"\"\t\"Databases "+i+"\"\t\"3\"\t\"CS\"\n");
            outFile.print("\"MATH"+i+"\"\t\"Discrete Math "+i+"\"\t\"4\"\t\"MATH\"\n");
            
         }   
         outFile.close();
      }
      catch(IOException ie)
      {
         ie.printStackTrace();
      }
   }

   /** 
       Creates a Sections file to be used in testing the students code
       The outFile.print lines below give the format for a line in this
       file. Also look at the HW description.

       @param size - numbers of rows to be output in courses files 
         (must be divisible by 6) 

   */
   public static void createSections(int size)
   {
      try
      {
         PrintStream outFile = new PrintStream(
            new FileOutputStream(SECTIONS_NAME));
            
         int j = 0;
         int k = 0;

         for(int i =0; i < size/6; i++)
         {  
            j = i / 3;
            k = i % 3;
           
            outFile.print("\""+k+"\"\t\"CS"+j+"\"\t\"Fall\"\t\"2005\"\t\"Pollett"+k+"\"\n");
            outFile.print("\""+k+"\"\t\"MATH"+j+"\"\t\"Spring\"\t\"2005\"\t\"Leibniz"+k+"\"\n");
            outFile.print("\""+k+"\"\t\"CS"+j+"\"\t\"Fall\"\t\"2006\"\t\"Gentzen"+k+"\"\n");
            outFile.print("\""+k+"\"\t\"MATH"+j+"\"\t\"Spring\"\t\"2006\"\t\"Godel"+k+"\"\n");
            outFile.print("\""+k+"\"\t\"CS"+j+"\"\t\"Fall\"\t\"2007\"\t\"Turing"+k+"\"\n");
            outFile.print("\""+k+"\"\t\"MATH"+j+"\"\t\"Spring\"\t\"2007\"\t\"Pollett"+k+"\"\n");
            
         }   
         outFile.close();
      }
      catch(IOException ie)
      {
         ie.printStackTrace();
      }   
   }

   public static void main (String args[])
   {
      String s[] = new String[2];
      s[0] = COURSES_NAME;
      s[1] = SECTIONS_NAME;
      
      int eatUpHeap[] = new int[EAT_HEAP_INTS]; // here's where we use up some of the heap
      
      for(int i=0; i < COURSES_SIZE.length; i++) //here's where we cycle through the tests
      {
         System.out.println("\nRunning Test "+i);
         createCourses(COURSES_SIZE[i]);
         createSections(SECTIONS_SIZE[i]);
         SectionProf.main(s);
      }
   }
    
   public static String COURSES_NAME = "Courses"; //filename for courses file
   public static String SECTIONS_NAME = "Sections"; //filename for sections file
   public static int COURSES_SIZE[] = {2, 100, 100000}; //test file sizes for courses file
   public static int SECTIONS_SIZE[] = {6, 100, 12};   //test file sizes for sections file
   public static int EAT_HEAP_INTS = 360400; /* how many ints worth of the heap to eat before
       starting students code */
}

Point Breakdown

Departmental coding guidelines for Java followed 1pt
Problem write-ups in Problems.txt (2pts/problem) 4pts
Program open and reads filename1 and filename2 1pts
Program produces the correct output on small test files 3pts
Program produces the correct output on large test file 1pt
Total10pts